package leetcode.每日一题;

import org.junit.Test;

import java.util.*;

/**
 * @author ：zsy
 * @date ：Created 2021/12/26 9:42
 * @description：https://leetcode-cn.com/problems/occurrences-after-bigram/
 */
public class Bigram分词 {
    @Test
    public void test() {
        Solution solution = new Solution();
        System.out.println(
                Arrays.toString(
                        solution.findOcurrences(
                                "alice is a good girl she is a good student",
                                "a",
                                "good")));
    }


    class Solution {
        public String[] findOcurrences(String text, String first, String second) {
            String[] strings = text.split(" ");
            ArrayList<String> list = new ArrayList<>();
            for (int i = 0; i < strings.length - 2; i++) {
                if (strings[i].equals(first) && strings[i + 1].equals(second)) {
                    list.add(strings[i + 2]);
                }
            }
            String[] ans = new String[list.size()];
            for (int i = 0; i < ans.length; i++) {
                ans[i] = list.get(i);
            }
            return ans;
        }
    }
}
